package com.lb.activity.sys.controller;

import com.lb.activity.sys.service.QuartzService;
import com.lb.activity.util.ResultUtil;
import com.lb.activity.vo.QuartzEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author 001030
 */
@RestController
public class QuartzController {

    @Autowired
    private QuartzService quartzService;


    /**
     * cron表达式页面
     * @return
     */
    @GetMapping("cron")
    public ModelAndView  cron(){
        return new ModelAndView("quartz/cron");
    }


    @GetMapping("task")
    public ModelAndView  task(){
        return new ModelAndView("quartz/quartz");
    }

    /**
     * 添加任务页面
     * @return
     */
    @GetMapping("toAddTask")
    public ModelAndView toAddTask(){
        return new ModelAndView("quartz/quartz-add");
    }

    /**
     * 添加任务
     * @param quartzEntity
     * @return
     */
    @PostMapping("addTask")
    public Object addTask(QuartzEntity quartzEntity){
        ResultUtil resultUtil = quartzService.addTask(quartzEntity);
        return resultUtil;
    }

    /**
     * 任务列表
     * @param quartz
     * @return
     */
    @GetMapping("tasks")
    public Object tasks(QuartzEntity quartz){
        ResultUtil resultUtil = quartzService.listQuartzEntity(quartz);
        return resultUtil;
    }

    /**
     * 开始任务
     * @param quartz
     * @return
     */
    @PostMapping("triggerTask")
    public  Object triggerTask(QuartzEntity quartz){
        ResultUtil resultUtil = quartzService.trigger(quartz);
        return resultUtil;
    }

    /**
     * 停止任务
     * @param quartz
     * @return
     */
    @PostMapping("stopTask")
    public  Object stopTask(QuartzEntity quartz){
        ResultUtil resultUtil = quartzService.stop(quartz);
        return resultUtil;
    }

    /**
     * 恢复任务
     * @param quartz
     * @return
     */
    @PostMapping("resumeTask")
    public  Object resumeTask(QuartzEntity quartz){
        ResultUtil resultUtil = quartzService.resume(quartz);
        return resultUtil;
    }


    /**
     * 删除任务
     * @param quartz
     * @return
     */
    @PostMapping("removeTaskData")
    public  Object removeTaskData(QuartzEntity quartz){
        ResultUtil resultUtil = quartzService.removeTask(quartz);
        return resultUtil;
    }

}
